import java.util.concurrent.atomic.AtomicReference;

/**
 * @auther:Alessio
 * @date:2021/1/11
 */

class User{
     String userName;
     int age;

    public String getUserName() {
        return userName;
    }

    public User() {}

    public int getAge() {
        return age;
    }

    public User(String userName, int age) {
        this.userName = userName;
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "userName='" + userName + '\'' +
                ", age=" + age +
                '}';
    }
}
public class AtomicReferenceDemo {

    public static void main(String[] args) {
        User zhangsan = new User("zhangsan", 18);
        User lisi = new User("lisi", 20);
        AtomicReference<User> atomicReference = new AtomicReference();

        atomicReference.set(zhangsan);
        System.out.println(atomicReference.compareAndSet(zhangsan, lisi)+" "+atomicReference.get());
        System.out.println(atomicReference.compareAndSet(zhangsan, lisi)+" "+atomicReference.get());
    }
}
